//
//  ContentView.swift
//  TanTan
//
//  Created by 于航 on 2024/9/15.
//

import SwiftUI
import SwiftData

struct ContentView: View {
    @StateObject var appState = AppState()
    var body: some View {
        VStack {
            switch appState.selectTab {
            case .home:
                HomeScreen()
                    .environmentObject(appState)
            case .live:
                Text("Live")
                    .environmentObject(appState)
            case .chat:
                MessageListScreen()
                    .environmentObject(appState)
            case .person:
                PersonView(user: User.me)
                    .environmentObject(appState)
            }
            if !appState.isFullScreen {
                Spacer()
                HStack {
                    tabItem(tab: .home, title: "MiaoTan")
                    tabItem(tab: .live, title: "Live")
                    tabItem(tab: .chat, title: "Chat")
                    tabItem(tab: .person, title: "Person")
                }
                .padding(6)
                .background(.gray.opacity(0.03))
            }
        }
    }
    
    func tabItem(tab: TabItem, title : String) ->some View {
        Button(action: {
            appState.selectTab = tab
        }, label: {
            VStack {
                Image(systemName: tab.rawValue)
                Text(title)
                    .font(.system(size: 10))
            }
            .foregroundStyle(appState.selectTab == tab ? Color.accentColor : .gray)
            .padding(.vertical, 8)
            .frame(maxWidth: .infinity)
            .background(.gray.opacity(0.01))
            .cornerRadius(18)
        })
    }
}

#Preview {
    ContentView()
}
